package org.example.spring.repository.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.example.spring.repository.mapper.DepartmentMapper;
import org.example.spring.repository.mapper.UserMapper;
import org.example.spring.repository.model.Department;
import org.example.spring.repository.model.User;
import org.example.spring.repository.service.IUserService;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * LuoYu
 * 2022/12/12 19:01
 **/
@Slf4j
@Service
@Primary
public class UserServiceImpl implements IUserService {


    @Resource
    private UserMapper userMapper;





    @Override
    @Transactional
    public void deleteUser(Long id) {

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createUserREQUIRED(String name,boolean hasThrow) {
        log.info("创建用户:{}",name);
        User build = User.builder().name(name).email(UUID.randomUUID().toString()).password("12356").salt("11").phoneNumber(UUID.randomUUID().toString()).build();
        int insert = userMapper.insert(build);
        if(hasThrow) {
            System.out.println(2 / 0);
        }
    }
}
